<html>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href='./css/style.css'>
    <title>dttan-web2</title>
    <body class="body">
        <div class="menu">
            <ul>
                <li><a href="#"> TRANG CHỦ</a></li>
                <li><a href="#">GIỚI THIỆU</a></li>
                <li><a href="#"><strong>SẢN PHẨM</strong></a>
                    <ul>
                        <li><a href="#">APPLE</a></li>
                        <li><a href="#">DELL</a></li>
                        <li><a href="#">SAMSUNG</a></li>
                        <li><a href="#">PANASONIC</a></li>
                    </ul>
                </li>   

                <li><a href="#"><strong>THIẾT BỊ MẠNG</strong></a>
                    <ul>
                        <li><a href="#">USB 3G</a></li>
                        <li><a href="#">HUB-SWICHT</a></li>
                        <li><a href="#">CABLE MẠNG</a></li>
                        <li><a href="#">KHÁC</a></li>
                    </ul>
                </li>
                <li><a href="#"> THIẾT BỊ VĂN PHÒNG</a>
                    <ul>
                        <li><a href="#">MÁY IN</a></li>
                        <li><a href="#">MÁY SCAN</a></li>
                        <li><a href="#">MÁY FAX</a></li>
                        <li><a href="#">MÁY TÍNH TIỀN</a></li>
                    </ul>
                </li>
                <li><a href="#">LIÊN HỆ</a></li>
            </ul>
            <div class="thanh"></div>
        </div>
        <div class="thanh"></div>
        <div class="hinh"></div>
        <div class="thanh"></div>
        <h3 align="center">
            <?php
            require_once './model/db.php';
            require_once './model/keywords.php';
            require_once './model/works.php';
            $works = new works();
            $work = $works->login($_GET['id'], NULL);
            ?>
            <?php
            if (!isset($_GET["page"]))
                $page = 1;
            else
                $page = $_GET["page"];
            ?>

            <div class="edit"> 
                <form method="post" action="index_edit.php?id=<?php echo $_GET['id'] ?>"     enctype="multipart/form-data">
                    <table>
                    <tr>
                        <td width="100px">ID:</td>
                        <td width="300px"><input type="text" name="id" size="65" value="<?php echo $work[0]['id']; ?>"></td><br>
                    </tr>

                    <tr>
                        <td width="100px">Name:</td>
                        <td width="300px"><input type="text" name="name" size="65" value="<?php echo $work[0]['name']; ?>"></td><br>
                    </tr>

                    <tr>
                        <td width="100px">Location:</td>
                        <td width="300px"><input type="text" name="location" size="65" value="<?php echo $work[0]['location']; ?>"></td><br>                    </tr>

                    <tr>
                        <td width="100px">company_address:</td>
                        <td><textarea name="company_address" rows="5" cols="50"><?php echo $work[0] ["company_address"] ?>"</textarea></div></td>
                    </tr>

                    <tr>
                        <td width="100px">Add image:</td>
                        <td width="300px"><input type="file" name="file" id="file"><br></td>                            
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" name="submit" value="Submit"></td>  
                    </tr>
                    </table>
                </form></div> 

            <?php
            if (isset($_POST['submit'])) {
                $allowedExts = array("gif", "jpeg", "jpg", "png");
                $temp = explode(".", $_FILES["file"]["name"]);
                $extension = end($temp);
                if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 10000000) && in_array($extension, $allowedExts)) {
                    if ($_FILES["file"]["error"] > 0) {
                        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
                    } else {
                        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
                        echo "Type: " . $_FILES["file"]["type"] . "<br>";
                        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
                        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
                        $file_name = $temp[0] . '-' . time() . '.' . $temp[1];
                        if (file_exists("./public/images/" . $_FILES["file"]["name"])) {
                            echo $_FILES["file"]["name"] . " already exists. ";
                        } else {
                            move_uploaded_file($_FILES["file"]["tmp_name"], "./public/images/" . $file_name);
                            echo "Stored in: " . "./public/images/" . $file_name;
                        }
                        $hinh_edit = "./public/images/" . $file_name;
                    }
                } else {
                    echo "Invalid file";
                }
                echo "<img src ='$hinh_edit' width = '100px'>";
            }
            ?>

            <br>
            <div id="footer" style="color: #ffffff">Trường Cao Đẳng Công Nghệ Thủ Đức.<br>Design by Tân Đoàn Thanh.</br></div>
    </body>
</html>

